package com.nis.bcreceiver;

import java.text.SimpleDateFormat;
import java.util.List;

import android.app.ActivityManager;
import android.content.Context;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class util {

	public static boolean isServiceRunning(Context mContext, String className) {
		boolean isRunning = false;
		ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);

		List<ActivityManager.RunningServiceInfo> serviceList = activityManager.getRunningServices(100);
		if (serviceList.size() == 0) {
			return false;
		}
		for (int i = 0; i < serviceList.size(); i++) {
			if (serviceList.get(i).service.getClassName().equals(className) == true) {
				isRunning = true;
				break;
			}
		}
		return isRunning;
	}
	public static boolean isEmpty(String str) {
		return (null == str || "".equals(str.trim())) ? true : false;
	}

	public static boolean isNotEmpty(String str) {
		if (isEmpty(str)) {
			return false;
		} else {
			return true;
		}
	}
	//时间戳得到时间
	public static String getDateByTimeStamp(String time) {
		if(time.contains(" ")|time.isEmpty()) {
			return time;
		}else {
			long time1 = Long.valueOf(time);
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			return format.format(time1);
		}
	}
	public static String getDoubleJsonArray(List<MsgBean> list) {
		JSONArray ja = new JSONArray();
		if (list != null && list.size() != 0) {
			JSONObject body;
			try {
				for (int i = 0; i < list.size(); i++) {
					body = new JSONObject();
					MsgBean msgBean = list.get(i);
					body.put("time", msgBean.when);
					body.put("from", msgBean.from);
					body.put("content", msgBean.content);
					ja.put(body);
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		return ja.toString();
	}
}
